﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchemaGraph.Interfaces;
using SchemaGraph.Interfaces.Vertexes;
using SchemaGraph.Interfaces.Edges;

namespace SchemaGraph.Generator
{
    public class GeneratorContext
    {
        GeneratorContext m_parent;
        Dictionary<string, IDatatypeVertex> m_datatypes = new Dictionary<string, IDatatypeVertex>();
        IDatatypeVertex m_vertex;

        public GeneratorContext(GeneratorContext parent, IDatatypeVertex vertex)
        {
            m_parent = parent;
            m_vertex = vertex;
        }

        public void AddDatatype(string typeName, IDatatypeVertex vertex)
        {
            m_datatypes.Add(typeName, vertex);
        }

        public IDatatypeVertex Lookup(string typeName)
        {
            IDatatypeVertex retval;
            if (!m_datatypes.TryGetValue(typeName, out retval)
                && m_parent != null)
                retval = m_parent.Lookup(typeName);
            return retval;
        }
    }
}
